package ext.tianma.model;

import wt.enterprise.Master;
import wt.fc.IdentificationObject;
import wt.fc.UniquelyIdentified;
import wt.iba.value.IBAHolder;
import wt.identity.DisplayIdentity;
import wt.util.WTException;

import com.ptc.windchill.annotations.metadata.Changeable;
import com.ptc.windchill.annotations.metadata.ColumnProperties;
import com.ptc.windchill.annotations.metadata.GenAsPersistable;
import com.ptc.windchill.annotations.metadata.GeneratedProperty;
import com.ptc.windchill.annotations.metadata.IconProperties;
import com.ptc.windchill.annotations.metadata.OracleTableSize;
import com.ptc.windchill.annotations.metadata.PropertyConstraints;
import com.ptc.windchill.annotations.metadata.StringCase;
import com.ptc.windchill.annotations.metadata.SupportedAPI;
import com.ptc.windchill.annotations.metadata.TableProperties;

@GenAsPersistable(superClass = Master.class, interfaces = { UniquelyIdentified.class, IBAHolder.class }, properties = {
        @GeneratedProperty(name = "number", type = String.class, supportedAPI = SupportedAPI.PUBLIC, constraints = @PropertyConstraints(
                stringCase = StringCase.UPPER_CASE,
                changeable = Changeable.VIA_OTHER_MEANS,
                required = true), columnProperties = @ColumnProperties(index = true, columnName = "TMNumber")),
        @GeneratedProperty(name = "name", type = String.class, supportedAPI = SupportedAPI.PUBLIC, constraints = @PropertyConstraints(
                changeable = Changeable.VIA_OTHER_MEANS,
                upperLimit = 4000,
                required = true)) }, tableProperties = @TableProperties(tableName = "TMObjectModelMaster", oracleTableSize = OracleTableSize.HUGE), iconProperties = @IconProperties(
        standardIcon = "netmarkets/images/TM/TMObjectMaster.gif",
        openIcon = "netmarkets/images/TM/TMObjectMaster.gif"))
public final class TMObjectModelMaster extends _TMObjectModelMaster {
    static final long serialVersionUID = 1;

    protected void setIdentificationObject(TMObjectModelMasterIdentity identity) {
        number = identity.getNumber();
        name = identity.getName();
    }

    public IdentificationObject getIdentificationObject() throws WTException {
        return TMObjectModelMasterIdentity.newTMObjectModelMasterIdentity(getNumber(), getName());
    }

    @Override
    public String getIdentity() {
        return ((DisplayIdentity) getDisplayIdentity()).getDisplayIdentifier().toString();
    }

    public static TMObjectModelMaster newTMObjectModelMaster() throws WTException {
        TMObjectModelMaster instance = new TMObjectModelMaster();
        instance.initialize();
        return instance;
    }

}
